<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "gky_qyh_approval".
 *
 * @property integer $id
 * @property integer $proposer_id
 * @property integer $approver_id
 * @property string $time
 * @property integer $type
 * @property string $approval_number
 * @property string $content
 * @property string $approval_detail
 * @property integer $is_approval
 */
class GkyQyhApproval extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gky_qyh_approval';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['proposer_id', 'time', 'approval_number', 'content', 'approval_detail', 'is_approval'], 'required'],
            [['proposer_id', 'approver_id', 'type', 'approval_number', 'is_approval'], 'integer'],
            [['time'], 'safe'],
            [['content', 'approval_detail'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'proposer_id' => 'Proposer ID',
            'approver_id' => 'Approver ID',
            'time' => 'Time',
            'type' => 'Type',
            'approval_number' => 'Approval Number',
            'content' => 'Content',
            'approval_detail' => 'Approval Detail',
            'is_approval' => 'Is Approval',
        ];
    }
    
    
      public static function getApproval(){
        $result = (new \yii\db\Query)
                ->select(['a.id','u.name proposer','u1.name approver'])
                ->from(['gky_qyh_approval a'])
                ->leftJoin('gky_qyh_user u','u.id=a.proposer_id')
                ->leftJoin('gky_qyh_user u1','u1.id=a.approver_id')
               ->all();
        
        return $result;
      }
}
